package bb.lanxing.model.bean;

import android.os.Parcel;
import android.os.Parcelable;
import com.alibaba.fastjson.JSON;
import com.baidu.mapapi.model.LatLng;
import com.baidu.platform.comapi.map.MapBundleKey;

import bb.lanxing.manager.PlaceCouponSharedPreference;
import bb.lanxing.model.data.IBasePOI;
import bb.lanxing.model.database.MapPOI;
import bb.lanxing.model.json.ServerUser;
import bb.lanxing.util.JsonUtil;
import bb.lanxing.util.text.TextUtils;
import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import org.json.JSONException;
import org.json.JSONObject;

public class Place implements Serializable, Parcelable, IBasePOI {
    public static final Parcelable.Creator<Place> CREATOR = new Parcelable.Creator<Place>() {

        public Place createFromParcel(Parcel parcel) {
            return new Place(parcel);
        }

        public Place[] newArray(int i) {
            return new Place[i];
        }
    };
    private long bikePlaceCouponCreateTime;
    private String bikePlaceFaceImages;
    private double bikePlaceGrade;
    private String bikePlaceIcon;
    private String bikePlacePhoneNum;
    private String bikePlaceWorkTime;
    private List<String> carPlaceImages;
    private List<PlaceService> chooseServeFlag;
    private Date createTime;
    private String description;
    private double distance;
    private boolean isAuthentication;
    private boolean isCollection;
    private double latitude;
    private String location;
    private double longitude;
    private MapPOI mapPoi;
    private int placeCommentCount;
    private List<PlaceDiscount> placeDiscountList;
    private List<PlaceService> serveFlag;
    private int serverId;
    private ServerUser serverUser;
    private String title;
    private long userId;

    @Override
    public int describeContents() {
        return 0;
    }

    public Place() {
        this.bikePlacePhoneNum = null;
    }

    public Place(JSONObject jSONObject) throws JSONException {
        this.bikePlacePhoneNum = null;
        setBikePlaceWorkTime(JsonUtil.getStringValue("service_time", jSONObject));
        setUserId(JsonUtil.getLongValue("user_id", jSONObject));
        setServerId(JsonUtil.getIntegerValue("id", jSONObject));
        setTitle(JsonUtil.getStringValue("title", jSONObject));
        setDescription(JsonUtil.getStringValue("description", jSONObject));
        setLatitude(JsonUtil.getDoubleValue("latitude", jSONObject));
        setLongitude(JsonUtil.getDoubleValue("longitude", jSONObject));
        setCreateTime(JsonUtil.getStringValue("create_time", jSONObject));
//        JSONObject objectValue = JsonUtil.getObjectValue(z.m, jSONObject);
//        if (objectValue != null) {
//            setServerUser(new ServerUser(objectValue));
//        }
        setBikePlaceIcon(JsonUtil.getStringValue("pic", jSONObject));
        setBikePlaceGrade(JsonUtil.getDoubleValue(MapBundleKey.MapObjKey.OBJ_LEVEL, jSONObject));
        setAuthentication(JsonUtil.getStringValue("checked", jSONObject).equals("1"));
        setLocation(JsonUtil.getStringValue("address", jSONObject));
        setBikePlacePhoneNum(JsonUtil.getStringValue("phone", jSONObject));
        setBikePlaceFaceImages(JsonUtil.getStringValue("images", jSONObject));
        if (JsonUtil.getArrayValue("service_items", jSONObject) != null) {
            setServeFlag(JSON.parseArray(JsonUtil.getArrayValue("service_items", jSONObject).toString(), PlaceService.class));
        }
        if (JsonUtil.getArrayValue("coupons", jSONObject) != null) {
            setPlaceDiscountList(JSON.parseArray(JsonUtil.getArrayValue("coupons", jSONObject).toString(), PlaceDiscount.class));
        }
        setCollection(JsonUtil.getIntegerValue("is_collection", jSONObject) != 1 ? false : true);
        setPlaceCommentCount(JsonUtil.getIntegerValue("comm_num", jSONObject));
    }

    protected Place(Parcel parcel) {
        this.bikePlacePhoneNum = null;
        this.userId = parcel.readLong();
        this.serverId = parcel.readInt();
        this.serverUser = (ServerUser) parcel.readParcelable(ServerUser.class.getClassLoader());
        this.title = parcel.readString();
        this.location = parcel.readString();
        this.bikePlacePhoneNum = parcel.readString();
        this.bikePlaceFaceImages = parcel.readString();
        this.carPlaceImages = parcel.createStringArrayList();
        this.bikePlaceWorkTime = parcel.readString();
        this.description = parcel.readString();
        this.latitude = parcel.readDouble();
        this.longitude = parcel.readDouble();
        this.bikePlaceIcon = parcel.readString();
        this.serveFlag = parcel.createTypedArrayList(PlaceService.CREATOR);
        this.chooseServeFlag = parcel.createTypedArrayList(PlaceService.CREATOR);
        this.placeDiscountList = parcel.createTypedArrayList(PlaceDiscount.CREATOR);
        this.bikePlaceGrade = parcel.readDouble();
        boolean z = true;
        this.isAuthentication = parcel.readByte() != 0;
        this.isCollection = parcel.readByte() == 0 ? false : z;
        this.placeCommentCount = parcel.readInt();
        this.bikePlaceCouponCreateTime = parcel.readLong();
        this.distance = parcel.readDouble();
    }

    @Override
    public void writeToParcel(Parcel parcel, int i) {
        parcel.writeLong(this.userId);
        parcel.writeInt(this.serverId);
//        parcel.writeParcelable(this.serverUser, i);
        parcel.writeString(this.title);
        parcel.writeString(this.location);
        parcel.writeString(this.bikePlacePhoneNum);
        parcel.writeString(this.bikePlaceFaceImages);
        parcel.writeStringList(this.carPlaceImages);
        parcel.writeString(this.bikePlaceWorkTime);
        parcel.writeString(this.description);
        parcel.writeDouble(this.latitude);
        parcel.writeDouble(this.longitude);
        parcel.writeString(this.bikePlaceIcon);
        parcel.writeTypedList(this.serveFlag);
        parcel.writeTypedList(this.chooseServeFlag);
        parcel.writeTypedList(this.placeDiscountList);
        parcel.writeDouble(this.bikePlaceGrade);
        parcel.writeByte(this.isAuthentication ? (byte) 1 : (byte) 0);
        parcel.writeByte(this.isCollection ? (byte) 1 : (byte) 0);
        parcel.writeInt(this.placeCommentCount);
        parcel.writeLong(this.bikePlaceCouponCreateTime);
        parcel.writeDouble(this.distance);
    }

    public long getUserId() {
        return this.userId;
    }

    public void setUserId(long j) {
        this.userId = j;
    }

    public boolean isCollection() {
        return this.isCollection;
    }

    public void setCollection(boolean z) {
        this.isCollection = z;
    }

    public String getBikePlaceFaceImages() {
        return this.bikePlaceFaceImages;
    }

    public void setBikePlaceFaceImages(String str) {
        this.bikePlaceFaceImages = str;
        setCarPlaceImages(str);
    }

    public int getPlaceCommentCount() {
        return this.placeCommentCount;
    }

    public void setPlaceCommentCount(int i) {
        this.placeCommentCount = i;
    }

    public void setLocation(String str) {
        this.location = str;
    }

    public void setBikePlacePhoneNum(String str) {
        this.bikePlacePhoneNum = str;
    }

    public void setCarPlaceImages(String str) {
        this.carPlaceImages = !TextUtils.isEmptyOrNull(str) ? Arrays.asList(str.split(",")) : null;
    }

    public void setBikePlaceWorkTime(String str) {
        this.bikePlaceWorkTime = str;
    }

    public String getLocation() {
        return this.location;
    }

    public String getBikePlacePhoneNum() {
        return this.bikePlacePhoneNum;
    }

    public List<String> getCarPlaceImages() {
        return this.carPlaceImages;
    }

    public String getBikePlaceWorkTime() {
        return this.bikePlaceWorkTime;
    }

    public String getBikePlaceIcon() {
        return this.bikePlaceIcon;
    }

    public List<PlaceService> getServeFlag() {
        return this.serveFlag;
    }

    public double getBikePlaceGrade() {
        return this.bikePlaceGrade;
    }

    public boolean isAuthentication() {
        return this.isAuthentication;
    }

    public void setCreateTime(Date date) {
        this.createTime = date;
    }

    public void setBikePlaceIcon(String str) {
        this.bikePlaceIcon = str;
    }

    public void setServeFlag(List<PlaceService> list) {
        this.serveFlag = list;
        if (list != null) {
            ArrayList arrayList = new ArrayList();
            for (int i = 0; i < list.size(); i++) {
                PlaceService placeService = list.get(i);
                if (placeService.getIsChoose()) {
                    arrayList.add(placeService);
                }
            }
            setChooseServeFlag(arrayList);
        }
    }

    public void setChooseServeFlag(List<PlaceService> list) {
        this.chooseServeFlag = list;
    }

    public List<PlaceService> getChooseServeFlag() {
        return this.chooseServeFlag;
    }

    public void setBikePlaceGrade(double d) {
        this.bikePlaceGrade = d;
    }

    public void setAuthentication(boolean z) {
        this.isAuthentication = z;
    }

    public int getServerId() {
        return this.serverId;
    }

    public void setServerId(int i) {
        this.serverId = i;
    }

    public ServerUser getServerUser() {
        return this.serverUser;
    }

    public void setServerUser(ServerUser serverUser) {
        this.serverUser = serverUser;
    }

    @Override
    public String getTitle() {
        return this.title;
    }

    public List<PlaceDiscount> getPlaceDiscountList() {
        return this.placeDiscountList;
    }

    public void setPlaceDiscountList(List<PlaceDiscount> list) {
        this.placeDiscountList = list;
        if (list == null || list.size() <= 0 || list.get(0).getBikePlaceCouponStartTime() == 0) {
            return;
        }
        setBikePlaceCouponCreateTime(list.get(0).getBikePlaceCouponStartTime());
    }

    @Override
    public String getImage() {
        return getBikePlaceIcon();
    }

    @Override
    public String getContent() {
        return getDescription();
    }

    @Override
    public void setTitle(String str) {
        this.title = str;
    }

    @Override
    public void setContent(String str) {
        setDescription(str);
    }

    @Override
    public void setImage(String str) {
        setBikePlaceIcon(str);
    }

    public String getDescription() {
        return this.description;
    }

    public void setDescription(String str) {
        this.description = str;
    }

    @Override
    public double getLatitude() {
        return this.latitude;
    }

    @Override
    public void setLatitude(double d) {
        this.latitude = d;
    }

    @Override
    public double getLongitude() {
        return this.longitude;
    }

    public double getDistance() {
        return this.distance;
    }

    public void setDistance(double d) {
        this.distance = d;
    }

    @Override
    public LatLng getLatLng() {
        return new LatLng(this.latitude, this.longitude);
    }

    @Override
    public void setLongitude(double d) {
        this.longitude = d;
    }

    @Override
    public void setLatLng(LatLng latLng) {
        this.latitude = latLng.latitude;
        this.longitude = latLng.longitude;
    }

    public Date getCreateTime() {
        return this.createTime;
    }

    public void setCreateTime(String str) {
        if (str != null) {
            try {
                this.createTime = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").parse(str);
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
    }

    public long getBikePlaceCouponCreateTime() {
        return this.bikePlaceCouponCreateTime;
    }

    public void setBikePlaceCouponCreateTime(long j) {
        this.bikePlaceCouponCreateTime = j;
        if (!PlaceCouponSharedPreference.getInstance().isShowNewPlaceCoupon(this.serverId)) {
            PlaceCouponSharedPreference.getInstance().setShowNewPlaceCoupon(this.serverId, j != PlaceCouponSharedPreference.getInstance().getBikePlaceCouponTime((long) this.serverId));
        }
        PlaceCouponSharedPreference.getInstance().setBikePlaceCouponTime(this.serverId, j);
    }

    public MapPOI getMapPoi() {
        return this.mapPoi;
    }

    public void setMapPoi(MapPOI mapPOI) {
        this.mapPoi = mapPOI;
    }


}
